<!--
  -    公表管理
  - Author: lengleng (wangiegie@gmail.com)
  -->
<template>
  <div class="execution">
    <!--<basic-container>
  </basic-container>-->
    <el-table
      :data="tableData"
      @on-load="getList"
      :show-header="false"
      border
      highlight-current-row
      :class="EditOnoff ? 'tb-edit' : 'tb-edit2'"
      @row-click="handleCurrentChange"
    >
      <el-table-column
        label="类型"
        width="350"
        :show-overflow-tooltip="true"
      >
        <template
          scope="scope"
          align="right"
        >
          <span>{{ scope.row.configType==1?'合同即将到期设置(月)：':(scope.row.configType==2?'逾期未缴费提醒设置(天)：':'展场停车费设置(小时)：') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="时间"
        width="150"
        :show-overflow-tooltip="true"
      >
        <template scope="scope">
          <el-input
            size="small"
            v-model="scope.row.configTimeValue"
            :placeholder="scope.row.configType==1?'月':(scope.row.configType==2?'天':'小时')"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="元"
        :show-overflow-tooltip="true"
      >
        <template scope="scope">
          <el-input
            v-if="scope.row.configType==3"
            size="small"
            v-model="scope.row.configAmoutValue"
            placeholder="元"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="180"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="handleComplete(scope.$index, scope.row)"
          >确定</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { fetchList, getObj, addObj, putObj, delObj } from '@/api/admin/othersetting/time/person'
import { tableOption } from '@/const/crud/admin/othersetting/time/person'
import { mapGetters } from 'vuex'

export default {
  name: 'othersetting',
  data () {
    return {
      inputForm: {
        id: '',
        configAmoutValue: '',
        configTimeValue: '',
        configType: '',
      },
      tableData: [],
      tableLoading: false,
      EditOnoff: false, //是否可编辑
      EditBefore: {}, //编辑之前的数据      
    }
  },
  mounted () {
    this.getList();
  },
  computed: {
    ...mapGetters(['elements', 'permissions'])
  },
  methods: {
    getList () {
      this.tableData = [{
        id: '1',
        configAmoutValue: '',
        configTimeValue: '4',
        configType: '1',
      }, {
        id: '2',
        configAmoutValue: '',
        configTimeValue: '4',
        configType: '2',
      }, {
        id: '3',
        configAmoutValue: '2',
        configTimeValue: '4',
        configType: '3',
      }]
      console.log(tableData)
      //this.tableLoading = true
      //fetchList(Object.assign({
      //  current: page.currentPage,
      //  size: page.pageSize
      //}, params, this.searchForm)).then(response => {
      //  this.tableData = response.data.data.records
      //  this.page.total = response.data.data.total
      //  this.tableLoading = false
      //}).catch(() => {
      //  this.tableLoading = false
      //})
    },
    //点击行
    handleCurrentChange (row, event, column) {
      let that = this;
      console.log(row.id, that.EditBefore.id);
      if (row.id == that.EditBefore.id) {
        that.EditOnoff = true;
      } else {
        that.EditOnoff = false;
      }
    },
    //完成
    handleComplete () {
      let that = this;
      that.EditOnoff = true;
      console.log(that.EditBefore);
      that.$confirm('是否完成此次编辑', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          that.GLOBAL.doPost(that.api.GLOBAL_user_update, JSON.stringify(that.EditBefore), function (res) {
            console.log(res);
            if (res.code == 200) {
              that.$message({ message: res.msg, type: 'success' });
              that.EditOnoff = false;
              //获取人员列表
              that.getByOrg();
            }
          });
        })
        .catch(() => { });
    }
  }
}
</script>
